import 'package:tiktokadult/hj_model/home/video_list_resp.dart';
import 'package:tiktokadult/hj_model/video_model.dart';
import 'package:tiktokadult/hj_utils/api_service/common_service.dart';
import 'package:tiktokadult/tools_base/base_list_controller.dart';

class AcgGameRecommendLogic extends ListBaseLogic {
  VideoModel? mediaModel;

  int currentPage = 1;

  AcgGameRecommendLogic({this.mediaModel});

  @override
  onReady() {
    super.onReady();
    loadData();
  }

  loadData({int pageNum = 1, bool showLoading = false, int size = 10}) async {
    dataList ??= [];
    VideoListResp? resp = await CommonService.getRecommendList(pageNumber: pageNum, pageSize: 10, vid: mediaModel?.id ?? '');

    if (resp != null) {
      currentPage = pageNum;
      if (pageNum == 1) dataList?.clear();
      dataList?.addAll(resp.videos ?? []);
    }
    update();
    resp?.hasNext == true ? refreshCtr?.loadComplete() : refreshCtr?.loadNoData();
    refreshCtr?.refreshCompleted();
  }

  loadMoreData() async => loadData(pageNum: currentPage + 1);
}
